<%@ page import="com.ems.model.Salary" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>添加薪资信息</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/salary.css">
</head>
<body>
<div class="container">
    <!-- 侧边栏 -->
    <div class="sidebar">
        <h2>管理后台</h2>
        <div class="user-info">
            <!-- 这里可以显示用户信息 -->
            <p>欢迎，管理员</p>
            <a href="#">退出登录</a>
        </div>
        <ul class="menu">
            <li><a href="emp1">员工管理</a></li>
            <li><a href="department">部门管理</a> </li>
            <li class="active"><a href="${pageContext.request.contextPath}/salary">薪资管理</a></li>
            <li><a href="attendance">考勤管理</a></li>
            <li><a href="register">注册管理员</a></li>
        </ul>
    </div>
    <!-- 主内容区域 -->
    <div class="main-content">
        <h1>添加薪资</h1>
        <!-- 显示错误消息或成功消息 -->
        <% if (request.getAttribute("error") != null) { %>
        <div class="error-message">
            <%= request.getAttribute("error") %>
        </div>
        <% } %>
        <% if (request.getAttribute("message") != null) { %>
        <div class="error-message" style="background-color: #d4edda; color: #155724; border-color: #c3e6cb;">
            <%= request.getAttribute("message") %>
        </div>
        <% } %>
        <!-- 添加薪资表单 -->
        <div class="salary-section">
            <h2>添加薪资</h2>
            <form action="${pageContext.request.contextPath}/salary" method="post" class="salary-form">
                <input type="hidden" name="action" value="addSalary">
                <div class="form-group">
                    <label for="empId">员工 ID</label>
                    <input type="text" id="empId" name="empId" required>
                </div>
                <div class="form-group">
                    <label for="amount">薪资金额</label>
                    <input type="number" id="amount" name="amount" step="0.01" required>
                </div>
                <div class="form-group">
                    <label for="payDate">支付日期</label>
                    <input type="date" id="payDate" name="payDate" required>
                </div>
                <button type="submit">添加薪资</button>
            </form>
        </div>
        <div class="salary-section">
            <h2>所有薪资信息</h2>
            <table class="data-table">
                <thead>
                <tr>
                    <th>薪资 ID</th>
                    <th>员工 ID</th>
                    <th>薪资金额</th>
                    <th>支付日期</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <%
                    java.util.List<Salary> salaries = (java.util.List<Salary>) request.getAttribute("salaries");
                    if (salaries != null) {
                        for (Salary salary : salaries) {
                %>
                <tr>
                    <td><%= salary.getSalaryId() %></td>
                    <td><%= salary.getEmpId() %></td>
                    <td><%= salary.getAmount() %></td>
                    <td><%= new SimpleDateFormat("yyyy-MM-dd").format(salary.getPayDate()) %></td>
                    <td>
                        <a href="salary?action=deleteSalary&salaryId=<%= salary.getSalaryId() %>">删除</a>                    </td>
                </tr>
                <%
                        }
                    }
                %>
                </tbody>
            </table>
        </div>
    </div>
</div>
</body>
</html>